﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using DynamicTestApp.DynamicXMLReader.DynamicXml;

namespace DynamicTest
{
    [TestClass]
    public class DynamicXmlTest1
    {
        [TestMethod]
        public void TestMethod1()
        {
        }


        [TestMethod]
        public void TestMethod2()
        {
            
            string xml = @"
                            <books pubdate='2009-05-20'>
                              <book price='45.99' title='Open Heart Surgery for Dummies'>
                                <id isbn10='4389880339'/>
                                <authors>
                                  <author>
                                    <name>
                                      <first>Mortimer</first>
                                      <middle>Q.</middle>
                                      <last>Snerdly</last>
                                    </name>
                                    <email address='mort@surgery.com'/>
                                  </author>
                                </authors>
                              </book>
                              <book price='32.75' title='Skydiving on a Budget'>
                                <id isbn='2129034454'/>
                                <authors>
                                  <author>
                                    <name>
                                      <first>Trudy</first>
                                      <middle>L.</middle>
                                      <last>Freefall</last>
                                    </name>
                                    <email address='tfreefall@jump.com'/>
                                  </author>
                                  <author>
                                    <name>
                                      <first>Bernard</first>
                                      <middle>M.</middle>
                                      <last>Fallson</last>
                                    </name>
                                    <email address='bernie@airborne.com'/>
                                  </author>
                                </authors>
                              </book>
                              <book price='22.40' title='How to Dismantle a Bomb'>
                                <authors>
                                  <author>
                                    <name>
                                      <first>Bono</first>
                                      <middle/>
                                      <last>Vox</last>
                                    </name>
                                    <email address='bono@u2.com'/>
                                  </author>
                                </authors>
                              </book>
                            </books> ";


            System.Diagnostics.Debug.WriteLine("#################################");
           
            // the variable xml contains the string text of an XML document
            dynamic dx = new DynamicXml(xml);

            string s01 = String.Format("PublicationDate='{0}'", dx.pubdate);
            string s02 = String.Format("BookCount='{0}'", dx.book.Count);
            foreach (dynamic b in dx.book)
            {
                string xxx = b.price.Value;
                string s03 = String.Format("Price='{0}'", b.price.Value);
                string s04 = String.Format("Title='{0}'", b.title.Value);
                string s05 = String.Format("AuthorCount='{0}'", b.authors.author.Count);
                foreach (dynamic a in b.authors.author)
                {
                    string s06 = String.Format("   ---- Begin Author ----");
                    string s07 = String.Format("   EmailAddress='{0}'", a.email.address);
                    string s08 = String.Format("   FirstName='{0}'", a.name.first.Value);
                    string s09 = String.Format("   MiddleName='{0}'", a.name.middle.Value);
                    string s10 = String.Format("   LastName='{0}'", a.name.last.Value);
                    string s11 = String.Format("   ----- End Author -----");
                }
                
            }


          
        }


    }
}
